package com.jason.campusinn.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.yuandian.wanna.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yuandian on 2015/6/2.
 */
public abstract class ChooseBankPopupWindow extends PopupWindow {

    public abstract void setSelect(String title);
    private View view;
    private Activity context;
    private ListView mListView;

    private List<String> mDatas= new ArrayList<>();
    private ArrayAdapter mAdapter ;

    public ChooseBankPopupWindow(Activity context, final List<String> mDatas){
        this.context = context;
        this.mDatas = mDatas;
        //初始化页面
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.popup_choose_bank, null);

        mListView=(ListView)view.findViewById(R.id.list_choose_bank_popup);
        mAdapter = new ArrayAdapter(context,R.layout.item_choose_bank_list,R.id.tv_item_choose_bank,mDatas);
        mListView.setAdapter(mAdapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                setSelect(mDatas.get(position));
                dismiss();
            }
        });

        setContentView(view);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.popupStyle);
//        实例化一个ColorDrawable颜色为半透明
//        ColorDrawable dw = new ColorDrawable(0xB0FFFFFF);
//        设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(new ColorDrawable());
//        this.setBackgroundDrawable(new BitmapDrawable());
        this.setOutsideTouchable(true);
        this.update();
    }
}
